package com.nf.health.app.homepage.adapter;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.nf.health.app.Constants;
import com.hyphenate.easeui.EaseConstant;
import com.nf.health.app.MyApplication;
import com.nf.health.app.R;
import com.nf.health.app.homepage.activity.HealthSelfTestingActivity;
import com.nf.health.app.healthstate.activity.HealthStateActivity;
import com.nf.health.app.login.activity.LoginActivity;
import com.nf.health.app.mydoctor.activity.MyNewDoctorActivity;
import com.nf.health.app.activity.global.RegisterNickActivity;
import com.nf.health.app.homepage.activity.SystemSchemeActivity;
import com.nf.health.app.activity.global.WebViewActivity;
import com.nf.health.app.activity.hostopal.MyHostipalListActivity;
import com.nf.health.app.activity.manage_health.KetiSignUpActivity;
import com.nf.health.app.adapter.AdsPagerAdapter;
import com.nf.health.app.adapter.HomePlanAdapter;
import com.nf.health.app.adapter.HomeSchemeAdapter;
import com.nf.health.app.adapter.HomeSolutionAdapter;
import com.nf.health.app.chatservice.activity.ChatActivity;
import com.nf.health.app.customview.CircleProgress;
import com.nf.health.app.inquiry.activity.FastInquiryActivity;
import com.nf.health.app.intervention_details.activity.InterventionDetailsActivity;
import com.nf.health.app.models.BannerBean;
import com.nf.health.app.models.HealthManagerStatus;
import com.nf.health.app.models.HealthNewsBean;
import com.nf.health.app.models.HealthStateBean;
import com.nf.health.app.models.HealthStateInfo;
import com.nf.health.app.models.MengHistoryModel;
import com.nf.health.app.models.SchemeBean;
import com.nf.health.app.models.SolutionSchemeBean;
import com.nf.health.app.models.TestPlan;
import com.nf.health.app.sport_recipe.activity.SportRecipeActivity;
import com.nf.health.app.utils.ActivityUtils;
import com.nf.health.app.utils.DensityUtil;
import com.nf.health.app.utils.DialogHelp;
import com.nf.health.app.utils.PreferenceHelper;
import com.nf.health.app.widget.InfiniteViewPager;
import com.nf.health.app.widget.indicator.CirclePageIndicator;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Jason on 2016/3/25.
 */
public class HomePageAdapter extends RecyclerView.Adapter implements View.OnClickListener {
    /**
     * 广告位
     */
    private static final int TYPE_ADS = 0;
    /**
     * 功能入口
     */
    private static final int TYPE_FUNCION_ENTRY = 1;
    /**
     * 解决方案 20161110新增功能 在第三个位置,后面一次后移
     */
    private static final int TYPE_SOLUTION_SCHEME = 3;
    /**
     * 健康方案
     */
    private static final int TYPE_HEALTH_SCHEME = 4;
    /**
     * 健康方案
     */
    private static final int TYPE_HEALTH_PLAN = 2;

    /**
     * 健康咨询带头部
     */
    private static final int TYPE_HEALTH_NEWS_HEADER = 5;
    /**
     * 健康咨询,放在最后面,有多个
     */
    private static final int TYPE_HEALTH_NEWS = 6;

    /**
     * 头部静态的item总数
     */

    private static int HEADER_ITEM_COUNT = 0;

    LayoutInflater inflater;

    private Activity act;

    /*********
     * 广告位的数据
     ***********/
    private ArrayList<BannerBean> bannerBeans;
    /********
     * 健康资讯的数据
     ***********/
    private HealthNewsBean healthNewsBean;
    /********
     * 功能入口： 将抗状态，查找医生，快速问诊，健康自测 的数据
     **********/
    private HealthStateBean healthStateBean;
    /**
     * 健康方案
     */
    List<SolutionSchemeBean> solutionBeans;
    /*******
     * 健康/健康  方案计划带头部
     ********/
    private List<SchemeBean> schemeBeans;
    private List<TestPlan> testPlans;
    private String uid;
    private String state;
    AdsViewHolder adsHolder;

    HealthStateInfo healthStateInfo;
    /*************
     * 医院首页医院列表
     ***********/
    private ArrayList<MengHistoryModel> mengHistoryModelList;
    private HealthManagerStatus healthManagerStatus;
    //private AdsPagerAdapter adsPagerAdapter ;
    public HomePageAdapter(Activity act, HealthStateInfo healthStateInfo) {
        this.act = act;
        this.healthStateInfo = healthStateInfo;
        inflater = LayoutInflater.from(act);
    }

    public void setHealthStateInfo(HealthStateInfo healthStateInfo) {
        this.healthStateInfo = healthStateInfo;
    }

    public void setMyNotifyChanged(HealthStateInfo healthStateInfo) {
        this.healthStateInfo = healthStateInfo;
        //notifyDataSetChanged();;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE_ADS) {   //广告位
            View viewAds = inflater.inflate(R.layout.item_home_ads, null);//1
            return new AdsViewHolder(viewAds);
        } else if (viewType == TYPE_FUNCION_ENTRY) {  //功能入口
            View viewFunEntry = inflater.inflate(R.layout.item_home_fun_entry2, null);
            return new FunEntryViewHolder(viewFunEntry);
        } else if (viewType == TYPE_SOLUTION_SCHEME) {// 解决方案
            View viewSolutionScheme = inflater.inflate(R.layout.item_home_solution_scheme, null);
            return new HealthSolutionViewHolder(viewSolutionScheme);
        } else if (viewType == TYPE_HEALTH_SCHEME) {// 健康/健康  方案计划带头部
            View viewHealthScheme = inflater.inflate(R.layout.item_home_health_scheme, null);
            return new HealthSchemeViewHolder(viewHealthScheme);
        } else if (viewType == TYPE_HEALTH_PLAN) {// 测量计划  新增
            View viewHealthScheme = inflater.inflate(R.layout.item_home_health_plan, null);
            return new HealthPlanViewHolder(viewHealthScheme);
        } else if (viewType == TYPE_HEALTH_NEWS) {//健康方案
            View viewHealthNews = inflater.inflate(R.layout.item_health_news_content, null);
            return new HealthNewsViewHolder(viewHealthNews);
        } else if (viewType == TYPE_HEALTH_NEWS_HEADER) {//健康资讯
            View viewHealthNewsheader = inflater.inflate(R.layout.item_health_news_header, null);
            return new HealthNewsHeaderViewHolder(viewHealthNewsheader);
        } else if (viewType == TYPE_HEALTH_NEWS_HEADER) {//健康资讯
            View viewHealthNewsheader = inflater.inflate(R.layout.item_health_news_header, null);
            return new HealthNewsHeaderViewHolder(viewHealthNewsheader);
        } else {
            return null;
        }
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof AdsViewHolder) {  //广告位
            adsHolder = ((AdsViewHolder) holder);
            adsHolder.viewpager.setAdapter(new AdsPagerAdapter(act, bannerBeans));
            adsHolder.viewpager.startAutoScroll();
            adsHolder.indicator.setViewPager(adsHolder.viewpager, 0);
            //由于某个控件获取了焦点，带ScrollView的控件例如(RecyclerView,ListView)会自己向下滑动一段距离，所以让靠上的控件先获取焦点，这样就不会向下滑动了
            adsHolder.viewpager.setFocusable(true);
            adsHolder.viewpager.setFocusableInTouchMode(true);
            adsHolder.viewpager.requestFocus();
        } else if (holder instanceof FunEntryViewHolder) {//功能入口
            FunEntryViewHolder funEntryHolder = ((FunEntryViewHolder) holder);
            if (mengHistoryModelList == null || mengHistoryModelList.size() == 0) {
                funEntryHolder.tv_cdoctor_01.setTextColor(ContextCompat.getColor(act, R.color.theme_color));
                String tip = "请前往<b>[健康银行]</b>";
                funEntryHolder.tv_cdoctor_01.setText(Html.fromHtml(tip));
                String tip2 = "添加医院 >>";
                funEntryHolder.tv_cdoctor_02.setText(Html.fromHtml(tip2));
                return;
            } else {
                funEntryHolder.tv_cdoctor_01.setTextColor(ContextCompat.getColor(act, R.color.black8));
                funEntryHolder.tv_cdoctor_02.setTextColor(ContextCompat.getColor(act, R.color.black8));
                if (mengHistoryModelList.size() == 1) {
                    funEntryHolder.tv_cdoctor_01.setVisibility(View.GONE);
                    funEntryHolder.tv_cdoctor_02.setGravity(Gravity.CENTER_VERTICAL);
                    MengHistoryModel mengHistoryModel1 = mengHistoryModelList.get(0);
                    funEntryHolder.tv_cdoctor_02.setText(mengHistoryModel1.getHname());
                } else if (mengHistoryModelList.size() == 2) {
                    funEntryHolder.tv_cdoctor_01.setVisibility(View.VISIBLE);
                    funEntryHolder.tv_cdoctor_02.setVisibility(View.VISIBLE);
                    funEntryHolder.tv_cdoctor_01.setText(mengHistoryModelList.get(0).getHname());
                    funEntryHolder.tv_cdoctor_02.setText(mengHistoryModelList.get(1).getHname());
                }
            }

        } else if (holder instanceof HealthSolutionViewHolder) {//解决方案
            HealthSolutionViewHolder solutionHolder = ((HealthSolutionViewHolder) holder);
            //没有解决方案时,整个item都隐藏
            if (solutionBeans == null || solutionBeans.size() == 0) {
                solutionHolder.rlSolutionSchemeHeader.setVisibility(View.GONE);
                solutionHolder.recyclerView.setVisibility(View.GONE);
            } else {
                solutionHolder.rlSolutionSchemeHeader.setVisibility(View.VISIBLE);
                solutionHolder.recyclerView.setVisibility(View.VISIBLE);
                solutionHolder.recyclerView.setAdapter(new HomeSolutionAdapter(act, solutionBeans));
            }
        } else if (holder instanceof HealthPlanViewHolder) {//测量计划
            HealthPlanViewHolder solutionHolder = ((HealthPlanViewHolder) holder);
            //没有解决方案时,整个item都隐藏
            if (testPlans == null || testPlans.size() == 0) {
                solutionHolder.rlHealthPlanHeader.setVisibility(View.GONE);
                solutionHolder.recyclerViewPlan.setVisibility(View.GONE);
            } else {
                solutionHolder.rlHealthPlanHeader.setVisibility(View.VISIBLE);
                solutionHolder.recyclerViewPlan.setVisibility(View.VISIBLE);
                solutionHolder.recyclerViewPlan.setAdapter(new HomePlanAdapter(act, testPlans,uid));
            }
        } else if (holder instanceof HealthSchemeViewHolder) {  // 推荐计划

            HealthSchemeViewHolder healthHolder = ((HealthSchemeViewHolder) holder);
            boolean isLogin = PreferenceHelper.getBoolean(PreferenceHelper.ISLOGIN, true);
            if (isLogin) {
                String username = PreferenceHelper.getString(PreferenceHelper.USERNAME, "");
                if (!TextUtils.isEmpty(username)) {
                    healthHolder.rlHealthSchemeHeader.setVisibility(View.VISIBLE);
                } else {
                    healthHolder.rlHealthSchemeHeader.setVisibility(View.GONE);
                }
            } else {
                healthHolder.rlHealthSchemeHeader.setVisibility(View.GONE);
            }
            Date d = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String dateNowStr = sdf.format(d);
            healthHolder.tvTime.setText(dateNowStr + "");
            if (schemeBeans != null) {
                if (schemeBeans.size() <= 0) {
                    healthHolder.tvDefaultView.setVisibility(View.VISIBLE);
                    healthHolder.recyclerView.setVisibility(View.INVISIBLE);
                } else {
                    healthHolder.tvDefaultView.setVisibility(View.GONE);
                    healthHolder.recyclerView.setVisibility(View.VISIBLE);
                    healthHolder.recyclerView.setAdapter(new HomeSchemeAdapter(schemeBeans, false));
                }
            } else {
                healthHolder.tvDefaultView.setVisibility(View.VISIBLE);
                healthHolder.recyclerView.setVisibility(View.INVISIBLE);
            }
        } else if (holder instanceof HealthNewsViewHolder) {  //健康方案
            try {//防止空指针之类的异常
                HealthNewsBean.ListEntity entity = healthNewsBean.getList().get(position - HEADER_ITEM_COUNT);
                HealthNewsViewHolder healthNewsHolder = ((HealthNewsViewHolder) holder);
                ImageLoader.getInstance().displayImage(entity.getImg(), healthNewsHolder.ivImg, MyApplication.optionsPic);
                healthNewsHolder.tvRegimenTitle.setText(entity.getTitle());
                healthNewsHolder.tvRegimenContent.setText(entity.getDescription());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (holder instanceof HealthNewsHeaderViewHolder) {  //健康资讯
            try {
                if (healthNewsBean.getNewsfocus() == null) {
                    return;
                }
                HealthNewsBean.NewsfocusEntity entity = healthNewsBean.getNewsfocus().get(0);
                HealthNewsHeaderViewHolder healthNewsHolder = ((HealthNewsHeaderViewHolder) holder);
                healthNewsHolder.tvDesc.setText(entity.getTitle());
                ImageLoader.getInstance().displayImage(entity.getImg(), healthNewsHolder.ivTop, MyApplication.optionsPic);
                healthNewsHolder.ivTop.setScaleType(ImageView.ScaleType.FIT_XY);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public int getItemCount() {
        HEADER_ITEM_COUNT = 1 + 1 + 1 + 1 + 1 + 1;//健康资讯上面item的数量(健康资讯有多个)
        if (healthNewsBean != null && healthNewsBean.getList() != null) {
            return HEADER_ITEM_COUNT + healthNewsBean.getList().size();
        }
        return HEADER_ITEM_COUNT;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_ADS;
        } else if (position == 1) {
            return TYPE_FUNCION_ENTRY;
        } else if (position == 2) {
            return TYPE_HEALTH_PLAN;
        } else if (position == 3) {
            return TYPE_SOLUTION_SCHEME;
        } else if (position == 4) {
            return TYPE_HEALTH_SCHEME;
        } else if (position == 5) {
            return TYPE_HEALTH_NEWS_HEADER;
        } else {
            return TYPE_HEALTH_NEWS;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_circle_progress:
                ActivityUtils.showActivity(act, HealthStateActivity.class);
                break;
            case R.id.rl_health_scheme_header:
                Toast.makeText(act, "添加新方案", Toast.LENGTH_SHORT).show();
                break;
            case R.id.rl_health_news_header:
                Toast.makeText(act, "更多资讯", Toast.LENGTH_SHORT).show();
                break;

        }
    }


    public void setAutoScroll(boolean isAutoScroll) {
        if (adsHolder != null) {
            if (isAutoScroll) {
                adsHolder.viewpager.startAutoScroll();
            } else {
                adsHolder.viewpager.stopAutoScroll();
            }
        }
    }

    /************
     * 刷新广告位的数据
     *************/
    public void setBannerDatas(ArrayList<BannerBean> bannerBeans) {
        this.bannerBeans = bannerBeans;
        getItemViewType(TYPE_ADS);
        notifyItemChanged(TYPE_ADS);
    }

    /********
     * 功能入口： 健康状态，查找医生，快速问诊，健康自测的刷新
     ********/
    public void setHealthState(HealthStateBean healthStateBean) {
        this.healthStateBean = healthStateBean;
        getItemViewType(TYPE_FUNCION_ENTRY);
        notifyItemChanged(TYPE_FUNCION_ENTRY);
    }


    /**
     * 解决方案
     *
     * @param solutionBeans
     */
    public void setHomeSolution(List<SolutionSchemeBean> solutionBeans) {
        this.solutionBeans = solutionBeans;
        getItemViewType(TYPE_SOLUTION_SCHEME);
        notifyItemChanged(TYPE_SOLUTION_SCHEME);
    }

    /**
     * 健康计划
     *
     * @param schemeBeans
     */
    public void setHealthPlan(List<SchemeBean> schemeBeans) {
        this.schemeBeans = schemeBeans;
        getItemViewType(TYPE_HEALTH_SCHEME);
        notifyItemChanged(TYPE_HEALTH_SCHEME);
    }

    /**
     * 测量计划
     *
     * @param
     */
    public void setTestPlan(List<TestPlan> testPlans,String uid) {//类型 有待修改
        this.testPlans = testPlans;
        this.uid = uid;
        getItemViewType(TYPE_HEALTH_PLAN);
        notifyItemChanged(TYPE_HEALTH_PLAN);
    }
    /**
     * 测量接话获取状态
     *
     * @param
     */
    public void setHealthManagerStatus(HealthManagerStatus healthManagerStatus) {//获取点击状态
        this.healthManagerStatus = healthManagerStatus;
        getItemViewType(TYPE_FUNCION_ENTRY);
        notifyItemChanged(TYPE_FUNCION_ENTRY);
    }

    /**
     * 健康资讯
     *
     * @param healthNewsBean
     */
    public void setHealthNews(HealthNewsBean healthNewsBean) {
        this.healthNewsBean = healthNewsBean;
        getItemViewType(TYPE_HEALTH_NEWS_HEADER);
        notifyItemChanged(TYPE_HEALTH_NEWS_HEADER);
    }


    /**
     * 活动医院
     * MengHistoryModelList
     *
     * @param
     */
    public void setListMengHistoryModel(ArrayList<MengHistoryModel> mengHistoryModelList) {
        this.mengHistoryModelList = mengHistoryModelList;
        getItemViewType(TYPE_FUNCION_ENTRY);
        notifyItemChanged(TYPE_FUNCION_ENTRY);
    }


    /**
     * 广告位
     */
    class AdsViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.viewpager)
        InfiniteViewPager viewpager;
        @Bind(R.id.indicator)
        CirclePageIndicator indicator;
        @Bind(R.id.rl_viewpager)
        RelativeLayout rl_viewpager;

        public AdsViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            ViewGroup.LayoutParams params = rl_viewpager.getLayoutParams();
            params.width = DensityUtil.getScreenIntWidth(act);
            params.height = DensityUtil.getScreenIntWidth(act) * 358 / 750;
            rl_viewpager.setLayoutParams(params);

        }
    }

    /**
     * 功能入口
     */
    class FunEntryViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        @Bind(R.id.tv_fast_inquiry)
        TextView tv_fast_inquiry;//快速问诊
        @Bind(R.id.ll_jkzt)
        LinearLayout ll_jkzt;//我的医生
        @Bind(R.id.tv_find_doctor)
        TextView tv_find_doctor;
        @Bind(R.id.tv_health_take_wake)
        TextView tv_health_take_wake;//健康运动
        @Bind(R.id.tv_health_self_testing)
        TextView tvHealthSelfTesting;//健康自测
        @Bind(R.id.tv_myhome_hospital)
        TextView tv_myhome_hospital;//我的医院
        @Bind(R.id.tv_cdoctor_02)
        TextView tv_cdoctor_02;
        @Bind(R.id.tv_cdoctor_01)
        TextView tv_cdoctor_01;
        @Bind(R.id.ll_mydortor_all)
        LinearLayout ll_mydortor_all;
        @Bind(R.id.fl_txt_parent)
        FrameLayout fl_txt_parent;
        @Bind(R.id.iv_show_current)
        ImageView iv_show_current;
        @Bind(R.id.ll_txt_parent)
        LinearLayout ll_txt_parent;
        @Bind(R.id.lin_health_mannger)//我的健康管理
                LinearLayout lin_health_mannger;
        @Bind(R.id.ll_all_health_mannger)
        LinearLayout ll_all_health_mannger;

        public FunEntryViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            ll_mydortor_all.setOnClickListener(this);
            tv_myhome_hospital.setOnClickListener(this);
            tvHealthSelfTesting.setOnClickListener(this);
            tv_health_take_wake.setOnClickListener(this);
            ll_jkzt.setOnClickListener(this);
            tv_fast_inquiry.setOnClickListener(this);
            ll_mydortor_all.setOnClickListener(this);
            iv_show_current.setOnClickListener(this);
            fl_txt_parent.setOnClickListener(this);
            ll_txt_parent.setOnClickListener(this);
            lin_health_mannger.setOnClickListener(this);
            tv_cdoctor_01.setOnClickListener(this);
            tv_cdoctor_02.setOnClickListener(this);
            fl_txt_parent.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.iv_circle_progress://运动处方
                    if (!checkRegister()) {
                        return;
                    } else {
                        ActivityUtils.showActivity(act, HealthStateActivity.class);
                    }
                    break;
                case R.id.ll_mydortor_all://我的医院列表
                case R.id.tv_myhome_hospital:
                case R.id.fl_txt_parent:
                case R.id.iv_show_current:
                case R.id.tv_cdoctor_01:
                case R.id.tv_cdoctor_02:
                    if (!checkRegister()) {
                        return;
                    } else {
                        Bundle bundle = new Bundle();
                        if (mengHistoryModelList != null && mengHistoryModelList.size() > 0) {
                            bundle.putSerializable(MyHostipalListActivity.TAG_MYLISTVIEW, mengHistoryModelList);
                        }
                        ActivityUtils.showActivity(act, MyHostipalListActivity.class, bundle);
                    }
                    break;
                case R.id.tv_fast_inquiry://快速问诊,inquiry包
                    if (!checkRegister()) {
                        return;
                    } else {
                        //检测是否完善注册信息
                        boolean registerInfoCompleted = PreferenceHelper.getBoolean(PreferenceHelper.REGISTER_INFO_COMPLETE, false);
                        if (!registerInfoCompleted) {
                            DialogHelp.getConfirmDialog(act, "亲,要先完善个人资料哦", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Bundle bundle = new Bundle();
                                    bundle.putString("type", "123");//跟注册时一样的type
                                    ActivityUtils.showActivity(act, RegisterNickActivity.class, bundle);
                                }
                            }).show();

                        } else {
                            ActivityUtils.showActivity(act, FastInquiryActivity.class);
                        }

                    }
                    break;
                case R.id.tv_health_self_testing:
                    //健康自测
                    ActivityUtils.showActivity(act, HealthSelfTestingActivity.class);
                    break;
                case R.id.ll_jkzt:
                    //查找医生--->改为我的医生
                    if (!checkRegister()) {
                        return;
                    }
                    ActivityUtils.showActivity(act, MyNewDoctorActivity.class);
                    break;
                case R.id.tv_health_take_wake:
                    //运动处方
                    if (!checkRegister()) {
                        return;
                    }
                    ActivityUtils.showActivity(act, SportRecipeActivity.class);
                    break;
                case R.id.lin_health_mannger:
                    if(healthManagerStatus == null){
                        return ;
                    }
                    //  -1无活动 3未购买设备,1未报名,2已报名
                    int status = healthManagerStatus.getState();
                    //我的健康管理
                    if(status == 1 || status == 3){
                        Intent intent = new Intent(act,KetiSignUpActivity.class);
                        intent.putExtra(Constants.KETI_STATE,status);
                        ActivityUtils.showActivity(act, intent);
                    }else if(status == 2){
                        //有服务,跳到聊天
                        Bundle bundle = new Bundle();
                        bundle.putString(EaseConstant.EXTRA_USER_ID, healthManagerStatus.getDoctorid());
                        bundle.putInt(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_SINGLE);
                        ActivityUtils.showActivity(act, ChatActivity.class, bundle);
                    }else if(status == -1){
                        Toast.makeText(act,"无活动",Toast.LENGTH_SHORT).show();
                    }

                    break;
            }
        }
    }

    /**
     * 解决方案 20161110新增
     */
    class HealthSolutionViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.rl_solution_scheme_header)
        RelativeLayout rlSolutionSchemeHeader;
        @Bind(R.id.recyclerView)
        RecyclerView recyclerView;

        public HealthSolutionViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            recyclerView.setHasFixedSize(true);
            LinearLayoutManager mLayoutManager = new LinearLayoutManager(act);
            recyclerView.setLayoutManager(mLayoutManager);
            recyclerView.setItemAnimator(new DefaultItemAnimator());
            //点击详情跳转到干预计划
            rlSolutionSchemeHeader.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intervention = new Intent(act, InterventionDetailsActivity.class);
                    ActivityUtils.showActivity(act, intervention);
                }
            });
        }
    }

    /**
     * 测量计划 20161110新增
     */
    class HealthPlanViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.plan_xiangqing)
        TextView planXiangqing;
        @Bind(R.id.rl_health_plan_header)
        RelativeLayout rlHealthPlanHeader;
        @Bind(R.id.recyclerView_plan)
        RecyclerView recyclerViewPlan;

        public HealthPlanViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            recyclerViewPlan.setHasFixedSize(true);
            LinearLayoutManager mLayoutManager = new LinearLayoutManager(act);
            recyclerViewPlan.setLayoutManager(mLayoutManager);
            recyclerViewPlan.setItemAnimator(new DefaultItemAnimator());


            rlHealthPlanHeader.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

//

                }
            });
        }
    }

    /**
     * 健康方案
     */
    class HealthSchemeViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.rl_health_scheme_header)
        RelativeLayout rlHealthSchemeHeader;//显示隐藏  添加方案layout
        @Bind(R.id.tv_time)
        TextView tvTime;
        @Bind(R.id.recyclerView)
        RecyclerView recyclerView;
        @Bind(R.id.tv_default_view)
        TextView tvDefaultView;

        public HealthSchemeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

            recyclerView.setHasFixedSize(true);
            LinearLayoutManager mLayoutManager = new LinearLayoutManager(act);
            recyclerView.setLayoutManager(mLayoutManager);
            recyclerView.setItemAnimator(new DefaultItemAnimator());


            rlHealthSchemeHeader.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //TODO
                    ActivityUtils.showActivity(v.getContext(), SystemSchemeActivity.class);

                }
            });

        }
    }

    /**
     * 健康资讯
     */
    class HealthNewsViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv_img)
        ImageView ivImg;
        @Bind(R.id.tv_regimen_title)
        TextView tvRegimenTitle;
        @Bind(R.id.tv_regimen_content)
        TextView tvRegimenContent;

        public HealthNewsViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //减去前面几种item的数量(随时有增减可能)
                    Bundle bundle = new Bundle();
                    bundle.putString(WebViewActivity.KEY_URL, healthNewsBean.getList().get(getPosition() - HEADER_ITEM_COUNT).getUrl());
                    bundle.putBoolean(WebViewActivity.KEY_IS_SHARE, true);
                    bundle.putString(WebViewActivity.KEY_SHARE_CONTENT, healthNewsBean.getList().get(getPosition() - HEADER_ITEM_COUNT).getDescription());
                    bundle.putString(WebViewActivity.KEY_TITLE, healthNewsBean.getList().get(getPosition() - HEADER_ITEM_COUNT).getTitle());
                    bundle.putString(WebViewActivity.KEY_IMAGE, healthNewsBean.getList().get(getPosition() - HEADER_ITEM_COUNT).getImg());
                    ActivityUtils.showActivity(act, WebViewActivity.class, bundle);
                }
            });
        }
    }

    /**
     * 带有头的健康资讯
     */
    class HealthNewsHeaderViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.re_health_new_top_image)
        ImageView ivTop;
        @Bind(R.id.tv_desc)
        TextView tvDesc;

        public HealthNewsHeaderViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            ivTop.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (healthNewsBean == null) {
                        return;
                    }
                    if (healthNewsBean.getNewsfocus() == null) {
                        return;
                    }
                    Bundle bundle = new Bundle();
                    bundle.putString(WebViewActivity.KEY_TITLE, healthNewsBean.getNewsfocus().get(0).getTitle());
                    bundle.putString(WebViewActivity.KEY_IMAGE, healthNewsBean.getNewsfocus().get(0).getImg());
                    bundle.putString(WebViewActivity.KEY_URL, healthNewsBean.getNewsfocus().get(0).getUrl());
                    bundle.putBoolean(WebViewActivity.KEY_IS_SHARE, true);
                    bundle.putString(WebViewActivity.KEY_SHARE_CONTENT, healthNewsBean.getNewsfocus().get(0).getDescription());
                    ActivityUtils.showActivity(act, WebViewActivity.class, bundle);
                }
            });
        }
    }

    /**
     * 检测是否已注册
     */
    public boolean checkRegister() {
        String username = PreferenceHelper.getString(PreferenceHelper.USERNAME, "");
        if (!TextUtils.isEmpty(username)) {
            //TODO 测试账号只有3位
            boolean isLogin = PreferenceHelper.getBoolean(PreferenceHelper.ISLOGIN, true);
            if (isLogin) {
                return isLogin;
            } else {
                ActivityUtils.showActivity(act, LoginActivity.class);
                return isLogin;
            }
        } else {
            ActivityUtils.showActivity(act, LoginActivity.class);
            return false;
        }
    }

    /**
     * 检测是否已注册
     */
    public boolean isLogin() {
        String username = PreferenceHelper.getString(PreferenceHelper.USERNAME, "");
        if (!TextUtils.isEmpty(username)) {
            //TODO 测试账号只有3位
            boolean isLogin = PreferenceHelper.getBoolean(PreferenceHelper.ISLOGIN, true);
            if (isLogin) {
                return isLogin;
            } else {
                return isLogin;
            }
        } else {
            return false;
        }
    }

    /**
     * 设置progress 用子线程完成动画效果
     *
     * @param view
     * @param target
     */
    private void setProgress(final CircleProgress view, final int target, final int total) {
        new Thread(new Runnable() {

            @Override
            public void run() {
                SystemClock.sleep(500);
                int progress = 0;
                while (progress <= target) {
                    view.setProgress(progress, total);
                    progress++;
                    SystemClock.sleep(10);
                }
            }
        }).start();
    }

    /*public AdsPagerAdapter getAdsPagerAdapter() {
        return adsPagerAdapter;
    }

    public void setAdsPagerAdapter(AdsPagerAdapter adsPagerAdapter) {
        this.adsPagerAdapter = adsPagerAdapter;
    }*/

    private float getCurrentProgress(final CircleProgress view) {
        return view.getCurrentProgress();
    }
}
